package com.eurabia.eggchat.controller.admin;


import com.eurabia.eggchat.VO.ResultVO;
import com.eurabia.eggchat.pojo.SysEggchatPost;
import com.eurabia.eggchat.pojo.SysEggchatReply;
import com.eurabia.eggchat.pojo.form.SysEggchatReplyForm;
import com.eurabia.eggchat.pojo.query.SysEggchatReplyQuery;
import com.eurabia.eggchat.service.SysEggchatReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

/**
 * SysEggchatReplyController 
 */
@Controller
@RequestMapping("/sysEggchatReply")
public class SysEggchatReplyController {
    private static final String LIST_PAGE = "modules/sysEggchatReply/list";
	private static final String SHOW_PAGE = "modules/sysEggchatReply/show";
    private static final String ADD_PAGE = "modules/sysEggchatReply/add";
    private static final String EDIT_PAGE = "modules/sysEggchatReply/edit";
    @Autowired
    private SysEggchatReplyService sysEggchatReplyService;
	
	/**
     * SysEggchatReply页面
     */
    @RequestMapping(value = "/listPage", method = RequestMethod.GET)
    public final String listPage() {
        return LIST_PAGE;
    }

    /**
     * 查询 SysEggchatReply
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public final ResultVO list(final SysEggchatReplyQuery query) {
        return new ResultVO(sysEggchatReplyService.findByPage(query));
    }

    /**
     * 查询 SysEggchatReply
     */
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    @ResponseBody
    public final ResultVO listAll(final SysEggchatReplyQuery query) {
        return new ResultVO(sysEggchatReplyService.find(query));
    }

    /**
     * 查看 SysEggchatReply
     */
    @GetMapping(value = "/show_{id}")
    @ResponseBody
    public final ResultVO showOne(@PathVariable("id") final String id) {
        ResultVO resultVO = new ResultVO();
        ArrayList<SysEggchatReply> sysEggchatReplys = new ArrayList<>();
        SysEggchatReply sysEggchatReply = sysEggchatReplyService.get(id);
        sysEggchatReplys.add(sysEggchatReply);
        resultVO.setData(sysEggchatReplys);
        return resultVO;
    }

    /**
     * 新增 SysEggchatReply
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public final String addPage() {
        return ADD_PAGE;
    }

    /**
     * 新增 SysEggchatReply
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO add(final SysEggchatReplyForm form) {
        sysEggchatReplyService.add(form);
        return new ResultVO();
    }

    /**
     * 修改 SysEggchatReply
     */
    @RequestMapping(value = "/edit_{id}", method = RequestMethod.GET)
    public final ModelAndView editPage(@PathVariable("id") final String id) {
        ModelAndView mav = new ModelAndView(EDIT_PAGE);
        mav.addObject("result", sysEggchatReplyService.get(id));
        return mav;
    }

    /**
     * 修改 SysEggchatReply
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO edit(final SysEggchatReplyForm form) {
        sysEggchatReplyService.update(form);
        return new ResultVO();
    }

    /**
     * 根据id删除 SysEggchatReply
     */
    @RequestMapping(value = "/delete_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO delete(@PathVariable("id") final String id) {
        sysEggchatReplyService.delete(id);
        return new ResultVO();
    }

    /**
     * 启用 SysEggchatReply
     */
    @RequestMapping(value = "/enabled_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO enabled(@PathVariable("id") final String id) {
        sysEggchatReplyService.changeEnabled(id, 1);
        return new ResultVO();
    }

    /**
     * 停用 SysEggchatReply
     */
    @RequestMapping(value = "/disabled_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO disabled(@PathVariable("id") final String id) {
        sysEggchatReplyService.changeEnabled(id, 2);
        return new ResultVO();
    }
}